package milkyway.hightech.customergui;

import milkyway.hightech.customer.BankCustomerView;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import java.lang.reflect.Method;

import java.util.HashMap;
import java.util.Map;
import java.util.Observable;
import java.util.ResourceBundle;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.border.AbstractBorder;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;

/**
 *
 * @author michael
 */
public class CustomerGUIMenu extends Observable implements ActionListener
{
    private JPanel menu;

    /**
     *
     * @param rb
     */
    public CustomerGUIMenu(ResourceBundle rb)
    {
        Object obj = rb.getObject("formElementValues");
        Map<String, String[]> map = (HashMap<String, String[]>)obj;
        Method[] methods = BankCustomerView.class.getMethods();
        JButton[] buttons = new JButton[methods.length];
        
        menu = new JPanel();
        menu.setSize(200, 600);
        menu.setPreferredSize(new Dimension(200, 600));
        
        menu.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED,
            Color.lightGray, Color.darkGray));
        
        menu.setBackground(Color.blue);

        for (int i = 0; i < buttons.length; i++)
        {
            buttons[i] = new JButton(map.get(methods[i].getName())[0]);
            buttons[i].setName(methods[i].getName());
            buttons[i].setSize(150, 21);
            buttons[i].setPreferredSize(new Dimension(190, 21));
            buttons[i].addActionListener(this);
            menu.add(buttons[i]);
        }
    }

    /**
     *
     * @return
     */
    public JPanel getMenu()
    {
        return menu;
    }

    /**
     *
     * @param e
     */
    @Override
    public void actionPerformed(ActionEvent e)
    {
        setChanged();

        String methodName = ((JButton)e.getSource()).getName();

        notifyObservers(methodName);
    }
}
